﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace NNCore
{
    public class NN
    {
        public NN() { }

        [XmlIgnore]
        private Layer[] layers;

       [XmlArray("LayerArray")]
       [XmlArrayItem("layer")]
        public Layer[] Layers
        {
            get { return layers; }
            set { layers = value; }
        }

        public Matrix Run(double[] input)
        {
            Matrix inputMatrix = Matrix.createHorVector(input);
            Matrix nettoInput;

            foreach (Layer tmpLayer in layers)
            {
                if (tmpLayer.WeightMatrix == null)
                {
                    nettoInput = inputMatrix;
                }
                else
                {
                    nettoInput = Matrix.UnsafeMultiplication(inputMatrix, tmpLayer.WeightMatrix);
                }

                tmpLayer.computeActivation(nettoInput);
                tmpLayer.computeOutput();

                inputMatrix = tmpLayer.Output;
            }

            return inputMatrix;
        }

        public void ResetActivationValues()
        {
            foreach (Layer tmp in layers)
            {
                tmp.ResetActivationValues();
            }
        }
    }
}
